<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link href="static/css/bootstrap.min.css" rel="stylesheet" />
		<link href="static/css/bootstrap-responsive.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<!-- 下拉框-->
		<link rel="stylesheet" href="static/css/chosen.css" />
		
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
		<style type="text/css">
		#dialog-add,#dialog-message,#dialog-comment{width:100%; height:100%; position:fixed; top:0px; z-index:10000; display:none;}
		.commitopacity{position:absolute; width:100%; height:500px; background:#7f7f7f; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5; top:0px; z-index:99999;}
		.commitbox{width:79%; padding-left:81px; padding-top:69px; position:absolute; top:0px; z-index:99999;}
		.commitbox_inner{width:96%; height:235px;  margin:6px auto; background:#efefef; border-radius:5px;}
		.commitbox_top{width:100%; height:230px; margin-bottom:10px; padding-top:10px; background:#FFF; border-radius:5px; box-shadow:1px 1px 3px #e8e8e8;}
		.commitbox_top textarea{width:95%; height:165px; display:block; margin:0px auto; border:0px;}
		.commitbox_cen{width:95%; height:40px; padding-top:10px;}
		.commitbox_cen div.left{float:left;background-size:15px; background-position:0px 3px; padding-left:18px; color:#f77500; font-size:16px; line-height:27px;}
		.commitbox_cen div.left img{width:30px;}
		.commitbox_cen div.right{float:right; margin-top:7px;}
		.commitbox_cen div.right span{cursor:pointer;}
		.commitbox_cen div.right span.save{border:solid 1px #c7c7c7; background:#6FB3E0; border-radius:3px; color:#FFF; padding:5px 10px;}
		.commitbox_cen div.right span.quxiao{border:solid 1px #f77400; background:#f77400; border-radius:3px; color:#FFF; padding:4px 9px;}
		</style>
		
	</head>
<body>
	<!-- 显示所有字段名称 -->
	<div class="container-fluid" id="main-container">
		<div id="page-content" class="clearfix">
		<!-- 添加属性  -->
		<input type="hidden" name="hcdname" id="hcdname" value="" />
		<input type="hidden" name="msgIndex" id="msgIndex" value="" />
		<input type="hidden" name="dtype" id="dtype" value="String" />
		<input type="hidden" name="isQian" id="isQian" value="是" />
		<form action="createCode/proCode.do" name="Form" id="Form" method="post">
			<input type="hidden" name="zindex" id="zindex" value="0">
			<div id="zhongxin">
			<table border="0">
				<tr>
					<td style="width:100px;text-align: right;">数据库表名：</td>
					<td>
					<!-- 获取所有表名 -->
					<select class="chzn-select" name="table_ID" id="table_id" data-placeholder="请选择表" style="width: 213px;">
						<option value="">请选择</option>
						<c:forEach items="${tableList}" var="table">
							<option value="${table }">${table }</option>
						</c:forEach>
				  	</select>
					</td>
					<td></td>
				</tr>
				<tr>
				<td style="line-height:8px;">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td style="width:100px;text-align: right;">项目包名：</td>
					<td colspan="1">
					<input type="text" name="package" id="package" value="com.sdkj.controller" style="width:280px" readonly="readonly" title="项目包名称"/>
					<input type="hidden" name="packageName" id="packageName" value=""/>
					</td>
					<td></td>
				</tr>
				<tr >
					<td style="width:100px;text-align: right;">工程类名：</td>
					<td><input type="text" name="objectName" id="objectName" value="" style="width:200px" title="工程类名称"/></td>
					<td>&nbsp;&nbsp;<font color="red" style="font-weight: bold;">类名首字母必须为大写字母</font></td>
				</tr>
				<tr >
					<td style="width:100px;text-align: right;">表前缀：</td>
					<td><input type="text" name="tabletop" id="tabletop" value="timeoa_" placeholder="这里输入表前缀" style="width:150px" title="表前缀"/></td>
					<td><a title="生成" class="btn btn-small btn-info" onclick="save();">&nbsp;生成&nbsp;</a></td>
				</tr>
			</table>
			<table id="table_report" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th class="center">属性名</th>
							<th class="center">类型</th>
							<th class="center">默认值</th>
							<th class="center">备注</th>
						</tr>
					</thead>
					<tbody id="fields"></tbody>
			</table>
			</div>
			<div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
		</form>
		</div>
	</div>
	
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script src="static/js/bootstrap.min.js"></script>
		<script src="static/js/ace-elements.min.js"></script>
		<script src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
		<script src="static/js/myjs/productCode.js"></script>
		<script type="text/javascript">
		$(top.hangge());
		$(function() {
			//下拉框
			$(".chzn-select").chosen();
			
			$("#table_id").change(function(){
				//发送Ajax至后台
				$.ajax({
					type: "POST",
					url: '<%=basePath%>head/getTable.do',
			    	data: {tableName:$(this).val()},
					dataType:'json',
					cache: false,
					success: function(data){
						//填写项目包名
						var tableName = $("#table_id").val();
						var tablePrefix = $("#tabletop").val();
						
						if(tableName.indexOf(tablePrefix) != -1){
							tableName = tableName.substring(tablePrefix.length,tableName.length);
						}
						
						var tables = tableName.toLowerCase().split("_");
						var className = "";
						for(var i in tables){
							className += tables[i].replace(tables[i].charAt(0), tables[i].charAt(0).toUpperCase());
						}
						$("#package").val("com.sdkj.controller."+className);
						$("#packageName").val(className.toLowerCase());
						$("#objectName").val(className);
						//填写类名
						if(data.status == 'success'){
							$("#fields").html("");
							var tableList = data.list;
							for(var i=0;i<tableList.length;i++){
								appendT(i,tableList[i]);
							}
						}
					}
				});
			})
			
			function appendT(i,value){
				var field = value;
				var comment = field.comment==""?"无":"";
				var result = field.field+'%%'+field.type+'%%'+field.defaultValue+'%%'+$("#isQian").val()+'%%'+comment;
				$("#fields").append(
					'<tr>'+
					'<td class="center"><input type="text" name="field0'+i+'" value="'+field.field+'"></td>'+
					'<td class="center"><input type="text" name="field1'+i+'" value="'+field.type+'"></td>'+
					'<td class="center"><input type="text" name="field2'+i+'" value="'+field.defaultValue+'"></td>'+
					'<td class="center"><input type="text" name="field3'+i+'" value="'+field.comment+'">'+
					'<input type="hidden" name="field'+i+'" value="'+result+'"></td>'+
					'</tr>'
				);
				i++;
				$("#zindex").val(i);
			}
		});
		
		</script>
	
</body>
</html>